
# 给测试报告添加列
from datetime import datetime

import pytest
from py.xml import html

def pytest_addoption(parser):
    parser.addoption("--file_name", default="testcase.xlsx")
    parser.addoption("--host_name", default="automated_testing")

@pytest.fixture()
def file_name(request):
    return request.config.getoption("--file_name")

@pytest.mark.optionalhook
def pytest_html_results_table_header(cells):
    cells.insert(2, html.th('Description'))
    cells.insert(1, html.th('Time', class_='sortable time', col="time"))
    cells.pop()


@pytest.mark.optionalhook
def pytest_html_results_table_row(report, cells):
    cells.insert(2, html.td(report.description))
    cells.insert(1, html.td(datetime.utcnow(), class_='col-time'))
    cells.pop()


#
#
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    report.description = str(item.function.__doc__)


